Add Compression best practices guide#52968
Add Compression best practices guide#52968alinpahontu2912 wants to merge 3 commits intodotnet:mainfrom
Conversation
rzikm
left a comment
There was a problem hiding this comment.
It's getting better, few additional comments.
| continue; | ||
|
|
||
| // Normalize and validate the path, same as the ZIP example. | ||
| string destPath = Path.GetFullPath(Path.Join(fullDestDir, entry.Name)); |
There was a problem hiding this comment.
Some samples use Path.Join, some Path.Combine, is there a meaningful difference between the two?
There was a problem hiding this comment.
Path.Combine returns just the second argument when it's a rooted path (starts with /), so Path.Combine("/dest", "/etc/passwd") gives /etc/passwd.
Path.Join always concatenates both. I will update safe samples to use Path.Join. difference here
| void TarStreamingRead(Stream archiveStream) | ||
| { | ||
| using var reader = new TarReader(archiveStream); | ||
| TarEntry? entry; | ||
| while ((entry = reader.GetNextEntry()) is not null) | ||
| { | ||
| if (entry.DataStream is not null) | ||
| { | ||
| string safePath = "output.bin"; | ||
| // Copy now — the stream becomes invalid after the next GetNextEntry() call | ||
| using var fileStream = File.Create(safePath); | ||
| entry.DataStream.CopyTo(fileStream); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I am not sure what this code snippet is supposed to illustrate
There was a problem hiding this comment.
It should show that the datastream must be consumed before the next getentry call. I'll redo it to make it clearer
|
|
||
| ## Data integrity | ||
|
|
||
| ZIP entries include a CRC-32 checksum that you can use to verify data hasn't been corrupted or tampered with. |
There was a problem hiding this comment.
I think you should also mention TAR CRC in the first paragraph, now users might assume that this section is Zip-only and skip the rest of it.
Summary
Add a guide explaining how to best work with Zip and Tar archives in .NET.
Internal previews